<?php
if (!defined('APPPATH')) exit('No direct script access allowed');

include_once(APPPATH.'libraries/api/core/MySQL.php');
include_once(APPPATH.'libraries/api/core/Services.php');

Class Multimedia extends Services {

	public static function multimediaGet($multimedia_id) {
		if(parent::checkArguments($multimedia_id)) {
			$query = "SELECT `multimedia_id`, `name`, `type`, `url`  FROM `multimedia` WHERE `multimedia_id` = $multimedia_id AND `deleted` != 1; ";
			$result = MySQL::selectGetRow($query);
			if(parent::check($result)) {
				return $result;
			} else {
				return array();
			}
		} else {
			return array();
		}
	}

	public static function multimediaSet($member_id, $name, $type, $url) {
		if(parent::checkArguments(array($member_id, $name, $type, $url))) {
			$query = "INSERT INTO `multimedia` (`member_id`, `name`, `type`, `url`, `deleted`) VALUES ($member_id, '$name', '$type', '$url', 0); ";
			$result = MySQL::update($query);
			if(parent::check($result)) {
				return true;
			} else {
				return false;
			}
		} else {
			return false;
		}
	}
	
	public static function multimediaMenuSet($member_id, $menu_id, $name, $type, $url) {
		if(parent::checkArguments(array($member_id, $menu_id, $name, $type, $url))) {
			$query = "INSERT INTO `multimedia` (`member_id`, `menu_id`, `name`, `type`, `url`, `deleted`) 
					  VALUES ($member_id, $menu_id, '$name', '$type', '$url', 0); ";
			$result = MySQL::update($query);
			if(parent::check($result)) {
				return true;
			} else {
				return false;
			}
		} else {
			return false;
		}
	}
        
	public static function multimediaDelete($multimedia_id) {
		if(parent::checkArguments($multimedia_id)) {
			$query = "UPDATE `multimedia` SET `deleted` = 1 WHERE `multimedia_id` = $multimedia_id;";
			$result = MySQL::update($query);
			if(parent::check($result)) {
				return true;
			} else {
				return false;
			}
		} else {
			return false;
		}
	}        
	
	public static function multimediaList() {
		$query = "SELECT `multimedia_id`, `name`, `type`, `url` FROM `multimedia` WHERE `deleted` != 1; ";
		$result = MySQL::selectGetArray($query);
		if(parent::check($result)) {
			return $result;
		} else {
			return array();
		}
	}
        
	public static function multimediaHomeList() {
		$query = "SELECT `multimedia_id`, `name`, `type`, `url`  FROM `multimedia` WHERE `menu_id` IS NULL AND `deleted` != 1; ";
		$result = MySQL::selectGetArray($query);
		if(parent::check($result)) {
			return $result;
		} else {
			return array();
		}
	}
        
	public static function multimediaMenuHomeList($menu_id) {
		if(parent::checkArguments($menu_id)) {
			$query = "SELECT `multimedia_id`, `name`, `type`, `url`  FROM `multimedia` WHERE `menu_id` = $menu_id AND `deleted` != 1; ";
			$result = MySQL::selectGetArray($query);
			if(parent::check($result)) {
				return $result;
			} else {
				return array();
			}
		} else {
			return array();
		}
	}
	
	public static function multimediaMenuList($menu_id) {
		if(parent::checkArguments($menu_id)) {
			$query = "SELECT `multimedia_id`, `name`, `type`, `url`  FROM `multimedia` WHERE `menu_id` = $menu_id AND `deleted` != 1; ";
			$result = MySQL::selectGetArray($query);
			if(parent::check($result)) {
				return $result;
			} else {
				return array();
			}
		} else {
			return array();
		}
	}	

}

?>
